# -*- coding;utf-8 -*-
"""
File name : CaoliaoQRcode.py.PY
Program IDE : PyCharm
Create file time: 2024/4/15 11:08
File Create By Author : 朱清闯
"""
import requests
import urllib.parse


def get_qrcode_and_store(url, file_path):
    # 构造URL参数
    cli_d = urllib.parse.quote(url)
    cli_f1 = urllib.parse.quote("微信：271774716")
    cli_f2 = urllib.parse.quote("官网：https://xxjstk.top")
    # 拼接URL
    url = "http://open-api.cli.im/cli-open-platform-service/v1/labelStyle/create"
    params = {
        "cliT": "B216",
        "cliD": cli_d,
        "return_file": "",
        "theme_color": "",
        "cliF1": cli_f1,
        "cliF2": cli_f2,
    }
    # 发送GET请求
    response = requests.get(url, params=params)
    # 检查响应状态码
    if response.status_code == 200:
        # 将返回的二进制数据流写入文件
        with open(file_path, "wb") as file:
            file.write(response.content)
            print("图片已保存为:", file_path)
            return True
    else:
        print(f"请求失败，状态码：{response.status_code}")
        print(response.text)  # 打印错误信息
        return False

